package com.hzhc.controller.storehouse;

import com.alibaba.fastjson2.JSONObject;
import com.hzhc.common.BaseController;
import com.hzhc.entity.CntrInfo;
import com.hzhc.entity.CntrYard;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.CntrInfoService;
import com.hzhc.service.CntrYardService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.StringUtils;
import com.hzhc.vo.CntrInfoVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 跳转电子库场图
 * </p>
 *
 * @author szjF
 * @since 2019-12-30
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/storehouse")
public class StorehouseController extends BaseController {

	private final CntrInfoService cntrInfoService;

	private final CntrYardService cntrYardService;

	/**
	 * 根据区域显示库场图贝位
	 */
	@ResponseBody
	@PostMapping("/getCntrBayInfo")
	public ResultUtil<JSONObject> getCntrBayInfo(@RequestBody CntrInfo cntrInfo) {
		JSONObject bayInfoBayArea = cntrInfoService.getCntrBayInfo(cntrInfo);
		return ResultUtil.build(bayInfoBayArea, ResultUtilCodeEnum.SUCCESS);
	}


	/**
	 * 库场图贝位
	 */
	@GetMapping("/detail/{bay}")
	public ResultUtil<JSONObject> getDetail(@PathVariable("bay") String bay) {
		String[] split = bay.split("-");

		//TODO 校验8+
		if("8+".equals(split[2])){

		}else{
			if(Integer.parseInt(split[2])<10){
				split[2]="0"+split[2];
			}else{
				split[2]=Integer.parseInt(split[2])+"";
			}
		}

		bay=split[0]+"-"+split[1]+"-"+split[2]+"-";
		List<CntrInfoVo> cntrList = cntrInfoService.selectCntrBybay(bay);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("bay", bay);
		jsonObject.put("cntrList", cntrList);
		return ResultUtil.build(jsonObject, ResultUtilCodeEnum.SUCCESS);
	}

	/**
	 * 库存行贝位图图
	 */
	@GetMapping("/rowbay/{bay}")
	public ResultUtil<JSONObject> rowbay(@PathVariable("bay") String bay) {
		CntrYard cntrYard =cntrYardService.selectRowCenBayAreaBay(bay);
		List<CntrInfoVo> cntrList = cntrInfoService.selectCntrBybay(bay);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("cntrYard",cntrYard);
		jsonObject.put("cntrList", cntrList);
		return ResultUtil.build(jsonObject, ResultUtilCodeEnum.SUCCESS);
	}
}


